#include <CGalaxyComponentDust.h>

double CGalaxyComponentDust::calculateIntensity(double I, CVector& p, double iscale) {
    CVector P;
    double z;
    double rad = getRadius(p, P, z);
    //height = 1;
    double winding = getWinding(rad)*componentParams.winding/(rad+1.0);
    z = getHeightModulation(z);
    //z = 0.1;

    if (z>0.001) 
      {
      
      double level = 15;
      
      double armVal = 1;
      if (componentParams.arm!=0) 
      	armVal = calculateArmValue(rad, P, componentParams.arm);
      
      
      double p2 = getPerlinCloudNoise(p, rad, winding, level, 0.5, componentParams.scale);
      //double p2 = getPerlinCloudNoise(p, 1.0, winding, level, 0.5, 1.0);
      //p2 *= (getPerlinCloudNoise(p*2.3, rad, winding*1, level, 0.5, params->dustScale));

      //p2 = 2.0;

      p2 = pow(p2,8);
      //      if (rad<0.01) return I;//rad = 0.01;
      double scale =CMath::SmoothStep(0, params->bulgeDust, rad);
      //cout << scale << endl;
      scale = pow(scale, 2.0);
      //scale = 1.0;
      //armVal = 1.0;
      double val = 1E1*(strength*p2)*scale*armVal*z*getRadialIntensity(rad)*pow(params->diskStarModifier,1)*1*iscale;
      //cout << val << endl;
      double s = 1.0/(val+1.0);
      I*=s;
      //I = scale;
      //I-=300*val;
          }
    return I;
  }
